package icg.util;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class DownFile
{
    private DownFile()
    {
    }
    public static void downFile(String s, String s1, String s2, boolean flag, HttpServletResponse httpservletresponse,HttpServletRequest httpservletrequest)
        throws FileNotFoundException,IOException
    {
        char c = '\u0400';
        FileInputStream fileinputstream = null;
        BufferedInputStream bufferedinputstream = null;
        ServletOutputStream servletoutputstream = null;
        Object obj = null;
        try
        {
            File file = new File(java.net.URLDecoder.decode(s));
            fileinputstream = new FileInputStream(file);
            int fileLen = (int)file.length();
            int i = 0;
            boolean flag1 = false;
            byte abyte0[] = new byte[fileLen];
            s2 = httpservletrequest.getHeader("user-agent");
            if(s2.indexOf("MSIE 5.5") != -1){                
                httpservletresponse.setHeader("Content-Type","doesn/matter;");
                httpservletresponse.setHeader("Content-Disposition","filename="+s1+";");

            } else {
                httpservletresponse.setHeader("Content-Type","application/octet-stream;");
                httpservletresponse.setHeader("Content-Disposition","attachment;filename="+s1+";");
            }

            httpservletresponse.setHeader("Content-Length", ""+fileLen);
            httpservletresponse.setHeader("Pragma", "no-cache;");

            servletoutputstream = httpservletresponse.getOutputStream();

            bufferedinputstream = new BufferedInputStream(fileinputstream);

            while((i = bufferedinputstream.read(abyte0, 0, fileLen)) != -1){
                servletoutputstream.write(abyte0, 0, i);
            }
        }
        catch( IOException e )
        {
            System.out.println(" Error in (in or to) : "+e);
        }
        catch(Exception exception)
        {
            System.out.println("downFile error!!! Exception = " + exception.toString());
        }
        finally
        {
            try
            {
                if(fileinputstream != null){
                    fileinputstream.close();
                }
                if(servletoutputstream != null){
                    servletoutputstream.close();
                }
            }
            catch(Exception exception2)
            {
                System.out.println("downFile error!!! Exception = " + exception2.toString());
            }
        }
    }
}
